<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<c:set var="path" value="${pageContext.request.contextPath }" />
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!-- 本框架基本脚本和样式 -->
<!-- 本框架基本脚本和样式 -->
<script type="text/javascript"
	src="${path }/resource/js/jquery-2.1.4.min.js"></script>
<script type="text/javascript"
	src="${path }/resource/js/systools/MBase.js"></script>
</head>
<body>
	<div class="ibox-content" id="warp">
		<!-- 搜索框部分start -->
		<div class="row">
			<div class="col-sm-9">
				<form class="form-inline" id="serchform">
					<%-- <input type="hidden" name="projId" id="projId" value="${param.projId}"> --%>
					<div class="form-group mr-20">
						<label for="exampleInputName2">通用区域</label> <select
							class="form-control autoFull" name="commonCaseArea" dataType="*"
							data-url="${path}/admin/dataDictionary/showDataDictionary"
							data-filed="name" data-value="name" data-param="{type:'通用区域'}">
							<option value="">--请选择通用区域--</option>
						</select>
					</div>

					<div class="form-group mr-20">
						<label for="exampleInputName2">类型</label> <select
							class="form-control autoFull" name="caseType" dataType="*"
							data-url="${path}/admin/dataDictionary/showDataDictionary"
							data-filed="name" data-value="name" data-param="{type:'用例类型'}">
							<option value="">--请选择用例类型--</option>
						</select>
					</div>

					<div class="form-group mr-20">
						<label for="exampleInputName2">优先级</label> <select
							class="form-control autoFull" name="grade">
							<option value="">--请选择优先级--</option>
							<option value="1">1</option>
							<option value="2">2</option>
							<option value="3">3</option>
							<option value="4">4</option>
						</select>
					</div>

					<button onclick="myGrid.serchData()" type="button"
						class="btn btn-info btn-sm">
						<i class="fa fa-search "></i> 搜索
					</button>
					<button type="reset" class="btn btn-info btn-sm">
						<i class="fa fa-refresh "></i> 重置
					</button>
				</form>
			</div>
		</div>
		<hr />

		<!-- <div style="position: relative; top: 40px;z-index: 12;width: 200px;">
			<button onclick="putIn()" type="button" class="btn btn-success btn-sm"><i class="fa fa-sign-in" ></i>  批量导入</button>
		</div>  -->
		<input type="hidden" name="projId" id="projId" value="${param.projId}">
		<div class="col-md-3">
			<label for="exampleInputName2">需要导入的功能模块</label> <select
				class="form-control select2" size="1" name="modelId" id="parentId">
				<option value="" selected="selected">---请选择功能模块---</option>
			</select>
		</div>

		<div class="row">
			<div class="col-md-12">
				<table id="mgrid">
					<thead>
						<tr>
							<th data-checkbox="true"></th>
							<th data-field="caseId">用例编号</th>
							<th data-field="title" data-formatter="buidTitle">标题</th>
							<th data-field="commonCaseArea">通用区域</th>
							<th data-field="caseType">用例类型</th>
							<th data-field="userStage">适用阶段</th>
							<th data-field="userName">创建人</th>
							<th data-field="createTime" data-formatter="MGrid.getTime">创建时间</th>
							<th data-align="center" data-width="195px" data-field="caseId"
								data-formatter="buidOperate">操作</th>
						</tr>
					</thead>
				</table>
			</div>
		</div>

		<div class="form-group ">
			<div class="col-sm-12 text-center">
				<!-- <button id="export" type="button" class="btn btn-info btn-sm">导出</button> -->
				<a href="javascript:;" id="export" class="btn btn-success radius"><i
					class="fa fa-check"></i> 导入</a>&nbsp;&nbsp;&nbsp;&nbsp; <a
					class="btn btn-danger radius" href="javascript:;"
					onclick="MTools.closeForm()"><i class="fa fa-close"></i> 关闭</a>
			</div>
		</div>

	</div>
</body>
<script src="${path }/resource/js/vue.js"></script>
<script type="text/javascript">
var myGrid;
$(function() {
	var delUrl = "";
	delUrl = "${path}/admin/commonUserCase/del";
	myGrid = MGrid.initGrid({
		url : "${path}/admin/commonUserCase/showList",
		delUrl : delUrl,
	});

});

var steps=[{stepNo:1,title:'',expectation:''}];
<c:if test="${obj ne null }">
steps=[];
<c:forEach var="item" items="${obj.stepsNoHistory }" >
	var step={stepNo:${item.stepNo},title:"${item.title}",expectation:"${item.expectation}" };
	steps.push(step);
</c:forEach>
</c:if>

console.log(steps);

	$(".select2").select2({
		'width' : '100%'
	});
	MTools.autoFullSelect();
	
	var myForm = MForm.initForm({
		invokeUrl : "${path}/admin/userCase/putIn",
		afterSubmit : function() {
			parent.myGrid.serchData();
		},
	});
	
	initModelList();
	//初始化项目模块
	function initModelList(projId) {
		$.AjaxProxy({
			a : false,
			c : false
		}).invoke(
				"${path}/admin/interfaceCate/all?projId="
						+ $(":input[name=projId]").val(), function(loj) {
					$("#parentId").createSelectTree(loj.attr("result").rows, {
						append : false,
						defaultValue : "${obj.modelId}"
					});
				});
	}
	
	function buidOperate(value, row, index){
		var html = '';
		html += '<button class="btn btn-default btn-sm mr-5" onClick="openShow('
				+ value
				+ ')" title="查看"><i class="fa fa-search"></i></buttoun>';
		
		return html;
	}
	
	//打开编辑界面
	function openShow(id) {
		layer.full(layer.open({
			type : 2,
			title : "编辑用例",
			area : [ MUI.SIZE_L, '400px' ],
			content : [ '${path}/admin/userCase/showFrom?id=' + id ]
		}));
	}
	
	function buidTitle(value,row,index){
		return '<span  class="badge badge-info" >'+row.grade+'</span> '+value;
	}
	
	 //批量导出
    $("#export").on("click",function(){
        var schList=[];
        var items = myGrid.initParam.$table.bootstrapTable('getSelections');
        var count=items.length;
        //拿到选择的模块
        var modelId = $("#parentId option:selected").val();
        //拿到工程id
        var projId =  $("#projId").val();
        if (count < 1) {
            layer.msg("请选择您要导出的数据", {
                icon : 5
            });
            return false;
        }
        for (var i = 0; i < items.length; i++) {
            schList.push(items[i].caseId);
        }
       	 /*
         var param={
    			c:true,
    			a:true,
    			p:{"modelId":modelId,
    				"projId":projId,
    				"caseIds":JSON.stringify(schList)			
    			},
    	};
        console.log(param);
    	$.AjaxProxy(param).invoke("${path}/admin/userCase/putIn",function(loj){    		
    		parent.location.reload();
    	}); */
        
       
    	//layer.confirm('确定到入所选的'+count+'个通用用例吗?', {icon: 3, title:'提示'}, function(index){
        	//layer.close(index);
       //	}); 
    		
    	   layer.full(layer.open({
				type : 2,
				content : ["${path}/admin/userCase/putIn?caseIds="+schList+"&modelId="+modelId+"&projId="+projId]
			}) );	
    	
    		MTools.closeForm();
    		parent.location.reload();
    });
	
        
</script>
</body>
</html>